<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        v-model="keyWord"
        placeholder=""
        style="width: 200px;"
        class="filter-item"
      />
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="onSeach"
        >搜索</el-button
      >
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="$router.push('/platform/create')"
        >新增</el-button
      >
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column align="center" label="平台名称">
        <template slot-scope="scope">
          <span>{{ scope.row.Name }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="AppId">
        <template slot-scope="scope">
          <span>{{ scope.row.WeixinAppId }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="AppSecret">
        <template slot-scope="scope">
          <span>{{ scope.row.WeixinAppSecret }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="Token">
        <template slot-scope="scope">
          <span>{{ scope.row.WeixinToken }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="是否启用" width="100px">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.IsEnable" disabled> </el-switch>
        </template>
      </el-table-column>

      <el-table-column align="center" label="EncodingAESKey">
        <template slot-scope="scope">
          <span>{{ scope.row.WeixinEncodingAESKey }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="Actions" width="120">
        <template slot-scope="scope">
          <router-link :to="'/platform/edit/' + scope.row.Id"
            ><el-button type="primary" size="small" icon="el-icon-edit"
              >编辑</el-button
            ></router-link
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.Page"
      :limit.sync="listQuery.PageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import Pagination from "@/components/Pagination"; // Secondary package based on el-pagination
export default {
  name: "PlatfromList",
  components: { Pagination },
  data() {
    return {
      list: null,
      total: 0,
      keyWord: "",
      listLoading: true,
      listQuery: {
        Name: "",
        Page: 1,
        PageSize: 10
      }
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    onSeach() {
      this.listQuery.Name = this.keyWord;
      this.listQuery.Page = 1;
      this.getList();
    },
    getList() {
      this.listLoading = true;
      this.$request.platform.getPlatformList(this.listQuery).then(response => {
        console.log(response);
        this.list = response.DataValue;
        this.total = response.Count;
        this.listLoading = false;
      });
    }
  }
};
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
